package com.cold.demo.sqlite;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: zyc
 */
@SpringBootApplication
public class SqliteApplication {
    public static void main(String[] args) {

        ConfigurableApplicationContext context = SpringApplication.run(SqliteApplication.class);

        JdbcTemplate jdbcTemplate = context.getBean(JdbcTemplate.class);

        KeyHolder    keyHolder    = new GeneratedKeyHolder();

        int          update       = jdbcTemplate.update("insert into user(id, name) values (?,?)", System.currentTimeMillis(), "周银昌" + System.currentTimeMillis());
        System.out.println("update："+update);

        List<Map<String, Object>> res = jdbcTemplate.query("select id,name from user",
                (rs, rowNum) -> {
                    Map<String, Object> map = new HashMap<>(2);
                    map.put("id", rs.getLong(1));
                    map.put("name", rs.getString(2));
                    return map;
                });
        System.out.println(res);

        context.close();
    }
}
